import { ref, onMounted } from 'vue'
import { getArticles } from '@/api/article'

export default function useArticles () {
  const articles = ref([])

  // 往常我们都写到 methods 中，然后在声明周期 mounted 中调用加载
  const loadArticles = async () => {
    const { data } = await getArticles()
    articles.value = data.articles
  }
  onMounted(loadArticles)
  return {
    loadArticles,
    articles
  }
}
